
import openpyxl
from openpyxl import load_workbook


def datas_from_excel(filename,sheetname):
    """
    获取excel表格中的数据，将每一行数据和表头组装起来，形成要使用的数据
    :param filename: 文件路径
    :param sheetname: 页签名
    :return: 组装好的数据
    """
    wb = load_workbook(filename)
    login_datas_sheet = wb[sheetname]
    keys = login_datas_sheet[1]
    datas_rows = login_datas_sheet.iter_rows(2)
    datas_lst = []
    for row in datas_rows:
        dct = dict(zip([key.value for key in keys],
                       [cell.value for cell in row]))
        datas_lst.append(dct)
    return datas_lst
